package com.yzc.tour;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yzc.pojo.Tour;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Yzc
 * @description 针对表【t_tour】的数据库操作Service实现
 * @createDate 2024-06-13 15:28:57
 */
@Service
public class TourServiceImpl extends ServiceImpl<TourMapper, Tour>
        implements TourService {

    @Autowired
    private TourMapper tourMapper;

    @Override
    public List<Tour> loadAll() {
        QueryWrapper<Tour> queryWrapper = new QueryWrapper<>();

        return tourMapper.selectList(queryWrapper);
    }

    @Override
    public List<Tour> selectInfos(Tour tourname) {
        QueryWrapper<Tour> queryWrapper = new QueryWrapper<>();
        if (tourname != null && tourname.getTourname() != null) {
            String likeValue = "%" + tourname.getTourname() + "%";
            queryWrapper.like("tourname", likeValue);
        }
        return tourMapper.selectList(queryWrapper);
    }

    @Override
    public Map deleteInfos(int tourid) {
        Map map = new HashMap();

        try {
            tourMapper.deleteById(tourid);
            map.put("result", "success");
        } catch (Exception e) {
            map.put("result", "error");
        }
        return map;
    }

    @Override
    public Map saveInfos(Tour tour) {
        Map map = new HashMap();

        try {
            tourMapper.saveInfos(tour);
            map.put("result", "success");
        } catch (Exception e) {
            map.put("result", "error");
        }
        return map;
    }

    @Override
    public Map updateInfos(Tour tour) {
        Map map = new HashMap();

        try {
            tourMapper.updateInfos(tour);
            map.put("result", "success");
        } catch (Exception e) {
            map.put("result", "error");
        }
        return map;
    }

    @Override
    public Tour getTourid(Integer tourid) {
        return tourMapper.selectById(tourid);
    }


}




